﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;

namespace Meow
{
    public class Job_Dismount: JobDriver
    {
        public Pawn Mount { get { return job.targetA.Thing as Pawn; } }

        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            return true;
        }
        protected override IEnumerable<Toil> MakeNewToils()
        {
            yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
            yield return new Toil()
            {
                defaultCompleteMode = ToilCompleteMode.Never,
                initAction = delegate
                {
                    
                    if (Mount != null)
                    {
                        var carrier = Mount.TryGetComp<Comp_ThingCarrier>();
                        if (carrier != null && carrier.Carrying == pawn)
                        {
                            carrier.Carry(null);
                        }
                    }

                    ReadyForNextToil();
                }
            };
        }
    }
}
